package com.huaguoguo.spring.context;

import cn.hutool.core.lang.Singleton;
import com.huaguoguo.spring.execption.BeansException;
import com.huaguoguo.spring.execption.NoSuchBeanDefinitionException;
import lombok.extern.slf4j.Slf4j;
import sun.rmi.runtime.Log;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.concurrent.ConcurrentHashMap;

/**
 * description: 注解容器
 * author:huaguoguo
 * Date:2018/12/6
 * Time:22:50
 */
@Slf4j
public class AnnotationApplicationContext implements ApplicationContext {

    /**
     * 存储所有bean的容器
     */
    private static Map<String, Object> singletonMap = new ConcurrentHashMap<>();

    public AnnotationApplicationContext(String basePackage) throws Exception {

        RegisterBeanDefinition register = new RegisterBeanDefinition();
        register.register(basePackage);
        BeanDefinitionScanner beanDefinitionScanner = new BeanDefinitionScanner(register);
        singletonMap = beanDefinitionScanner.sacnner();
    }

    /**
     * 根据beanName获取容器中的bean
     *
     * @param beanName
     * @return
     */
    public Object getBean(String beanName) {
        return singletonMap.get(beanName);
    }

    @Override
    public <T> T getBean(String name, Class<T> requiredType) throws BeansException {
        return null;
    }

    /**
     * @param name the name of the bean to retrieve
     * @param args arguments to use when creating a bean instance using explicit arguments
     *             (only applied when creating a new instance as opposed to retrieving an existing one)
     * @return an instance of the bean
     * @throws BeansException if the bean could not be created
     */
    @Override
    public Object getBean(String name, Object... args) throws BeansException {
        return null;
    }

    /**
     * 根据bean类型获取bean，如果有多个默认取bean类名首字母小写的bean
     * 例如： 有多个User类型的bean，默认取bean的name为user的bean
     *
     * @param requiredType
     * @return
     * @throws BeansException
     */
    @Override
    public <T> T getBean(Class<T> requiredType) throws BeansException {
        return null;
    }

    @Override
    public <T> T getBean(Class<T> requiredType, Object... args) throws BeansException {
        return null;
    }

    @Override
    public boolean containsBean(String name) {
        return false;
    }

    @Override
    public boolean isSingleton(String name) throws NoSuchBeanDefinitionException {
        return false;
    }

    @Override
    public boolean isPrototype(String name) throws NoSuchBeanDefinitionException {
        return false;
    }

    @Override
    public boolean isTypeMatch(String name, Class<?> typeToMatch) throws NoSuchBeanDefinitionException {
        return false;
    }

    @Override
    public Class<?> getType(String name) throws NoSuchBeanDefinitionException {
        return null;
    }

    @Override
    public String[] getAliases(String name) {
        return new String[0];
    }


    /**
     * 根据bean的名称和类型获取对应的bean
     *
     * @param clazz
     * @param beanName
     * @return
     */
    @Override
    public <T> T getBean(Class<T> clazz, String beanName) {
        return null;
    }
}
